package com.idlefish.flutterboost.action;

import android.annotation.SuppressLint;
import android.text.TextUtils;
import android.util.Log;

import androidx.annotation.NonNull;

import com.google.gson.JsonElement;
import com.google.gson.JsonObject;
import com.google.gson.JsonParser;
import com.idlefish.flutterboost.FlutterJsonUtil;
import com.idlefish.flutterboost.Messages;
import com.idlefish.flutterboost.intef.MethodCallAction;

import io.flutter.plugin.common.MethodCall;
import io.flutter.plugin.common.MethodChannel;

public class MethodActionRefreshNotify implements MethodCallAction {

    @SuppressLint("LongLogTag")
    @Override
    public void doAction(Messages.NativeRouterApi api, @NonNull MethodCall methodCall, @NonNull MethodChannel.Result result) {
        Messages.CommonParams params = new Messages.CommonParams();
        String json = FlutterJsonUtil.toJson(methodCall.arguments);
        if (TextUtils.isEmpty(json)) {
            return;
        }
        Log.e("MethodActionRefreshNotify", json);
        JsonElement jsonElement = JsonParser.parseString(json);
        if (jsonElement.isJsonObject()) {
            params.setPageName(json);
            api.refreshNotify(params);
        }
    }
}
